﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MINERP.DAL.OverOrder;
using MINERP.DAL.Statistics;

namespace MINERP.Statistics.Forms
{
    public partial class FrmOutProductStat : Form
    {
        OutShopDAL _dal;
        public FrmOutProductStat()
        {
            InitializeComponent();
            _dal = new OutShopDAL();
        }

        private void FrmOutProductStat_Load(object sender, EventArgs e)
        {
            //初始化委外商下拉列表、二个时间列表
            DEStart.DateTime = DateTime.Now.Date;
            DEEnd.DateTime = DateTime.Now.Date;

            LUEOutShop.Properties.DataSource = _dal.GetAllOutShop();
            LUEOutShop.Properties.DisplayMember = "OutShopName";
            LUEOutShop.Properties.ValueMember = "OutShopId";
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            simpleButton1.Enabled = false;
            if (LUEOutShop.EditValue == null)
            {
                MessageBox.Show("请选择一个委外加工商");
                simpleButton1.Enabled = true;
                return;
            }
            int outShopId=(int)LUEOutShop.EditValue;
            
            DataSet dsResult= OutShopStatDAL.GetProductsStat(outShopId, DEStart.DateTime.Date, DEEnd.DateTime.Date.AddDays(1));
            dsResult.WriteXml(@"C:\windows\xmlData\委外商产品统计.xml", XmlWriteMode.WriteSchema);
            report1.Load(Application.StartupPath + "\\委外商产品汇总.frx");
            report1.RegisterData(dsResult);  
            report1.SetParameterValue("outShopName", LUEOutShop.Text);
            report1.SetParameterValue("startTime", DEStart.DateTime.Date);
            report1.SetParameterValue("endTime", DEEnd.DateTime.Date);
            report1.Preview = previewControl1;
            previewControl1.Refresh();

            report1.Show();
            simpleButton1.Enabled = true;
            //dsResult.WriteXmlSchema(Application.StartupPath + "");
        }
    }
}
